package org.javaboy.virtual_thread_demo.service;

import org.springframework.core.task.AsyncTaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

@Service
public class HelloService {

    /**
     * 开启虚拟线程之后，定时任务也在虚拟线程中执行了
     */
//    @Scheduled(fixedRate = 1000)
    public void hello() {
        System.out.println("HelloService:hello:" + Thread.currentThread());
    }

    /**
     * @Async 注解默认也是有一个线程池，这个线程池类型就是 AsyncTaskExecutor。
     *
     * 开启虚拟线程之后，那么 @Async 注解标记的方法就在虚拟线程中执行了
     */
    @Async
    public void hello2() {
        System.out.println("hello2:" + Thread.currentThread());
    }

}
